<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        // 获取数组中每个元素出现的次数 ["c", "a", "z", "a", "x", "a"]

        var arr = ["c", "a", "z", "a", "x", "a"];
        var obj = {};
        for (var i = 0; i < arr.length; i++) {
            if (obj[arr[i]]) {
                obj[arr[i]]++;
            } else {
                obj[arr[i]] = 1;
            }
        }
        // console.log(obj);
        var s = '';
        for (var k in obj) {
            // console.log(obj[k]);
            s = k;
            console.log(s + '出现' + obj[k] + '次');
        }


    </script>
</body>

</html>